import {defineStore} from 'pinia'

import { ref } from 'vue'

export const useUserStore  = defineStore('user',()=>{
    const userInfo = ref()
    
    function updateUserInfo(info = {}) {
        userInfo.value = info
        sessionStorage.setItem("userInfo",JSON.stringify(info))
    }

    function getUserInfo(){
        return JSON.parse(sessionStorage.getItem("userInfo") || '{}' )
    }

    //页面刷新后重新加载store
    function reload(){
        userInfo.value = getUserInfo()
    }


    return {
        userInfo,
        updateUserInfo,
        getUserInfo,
        reload
    }


})

